#pragma once
//interface header
#include <memory>

namespace MEM
{
	class HeapImp;

	class Heap
	{
	public:

		//intro: create a heap
		//arguments: pointer of a mem out of this heap, size of the mem
		//arguments: size of the heap
		//usage
		//Heap* outer_heap = new Heap(new char[1024],1024);
		//Heap* Iner_heap = new Heap(outer_heap->alloc(512),512);
		Heap(void* ptr,size_t s);
		//Heap(size_t s);
		
		//de-constructor
		~Heap();
		
		//intro: alloc a s size memory, it contains debug info like the file name and the line number 
		//       the resource failures will throw exception
		//usage: p = memmgr.Mem_new(512,__FILE__,__LINE__);
		void* Mem_new(size_t s, const char* fileName, int lineNum,int type= 'none');

		//intro: handle the mem block outside of the heap
		//usage: memmgr.handle(p,1024);//p could be char[1024];
		//bool Handle(void* ptr, size_t s);

		//intro: delete a pointer
		//usage: memmgr.Mem_delete(p);
		void Mem_delete(void* ptr);
		
		//intro: create a sub-heap in this heap
		//arguments: the sub heap size
		//usage
		//Heap* sub_heap = Iner_heap->subHeap(128);
		Heap* subHeap(size_t s);
		
		//free all the pointers in heap
		void TotalFreeMem();
		
		//intro: return the largest free block in heap
		size_t LargestFreeBlock();
		
		//intro: verify the heap
		void Verify();
		
		//intro: dump the usage of the heap, output it to screen
		void Dump();

		//intro: dump usage by type
		void Dump(int type);

		//intro: check whether it is the dangling pointer
		bool IsPtrValid(void* ptr);

		//intro: get worst case usage memory, I return the biggest size allocated memory
		size_t GetWorstCaseUsageMemory();

		//intro:check memory leak
		void checkLeak();

	private:

		HeapImp* m_heapImp;
	};

}

